package com.chuanyang.driverh.mainorder.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.responseresult.OrderDetailData;
import com.chuanyang.driverh.responseresult.WaybillDetailsData;

import java.util.List;


public class MarkerPoinAdapter extends BaseAdapter {
    private Context context;
    private List passPoints;
    private boolean isOrder;
    private ViewHolder holder;

    public MarkerPoinAdapter(Context context, List passPoints, boolean isOrder) {
        this.context = context;
        this.passPoints = passPoints;
        this.isOrder = isOrder;
    }

    @Override
    public int getCount() {
        return passPoints.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        String address = "";
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.order_item_markerpoint, null);
            holder = new ViewHolder();
            holder.tv_marker_point = (TextView) convertView.findViewById(R.id.tv_marker_point);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (isOrder) {
            OrderDetailData.PassPointsBean bean1 = (OrderDetailData.PassPointsBean) passPoints.get(position);
            if (!TextUtils.isEmpty(bean1.getCity())) {
                address = address + bean1.getCity();
            }
            if (!TextUtils.isEmpty(bean1.getRegions())) {
                address = address + bean1.getRegions();
            }

            holder.tv_marker_point.setText(address);


        }
        else {
            WaybillDetailsData.PassPointsBean bean2 = (WaybillDetailsData.PassPointsBean) passPoints.get(position);
            if (!TextUtils.isEmpty(bean2.getCity())) {
                address = address + bean2.getCity();
            }
            if (!TextUtils.isEmpty(bean2.getRegions())) {
                address = address + bean2.getRegions();
            }
            holder.tv_marker_point.setText(address);
        }
        return convertView;
    }

    class ViewHolder {
        private TextView tv_marker_point;
    }
}
